set_toolchains("clang")
-- 设置项目名称和版本
set_project("CompileServer")
set_version("1.0")
add_rules("mode.debug", "mode.release")

-- 设置C++标准
set_languages("cxx20")

-- 设置输出目录
if is_mode("debug") then
    set_targetdir("bin/Debug")
else
    set_targetdir("bin/Release")
end


-- 添加头文件搜索路径
add_includedirs("include", "src/header", "protobuf/include","src/client")

-- 添加库搜索路径
add_linkdirs("/usr/lib", "/usr/local/lib", "lib", "protobuf/lib")

-- 遍历src目录下的所有源文件
for _, sourcefile in ipairs(os.files("src/*.cc", "src/*.cpp", "src/*.c", "src/*.cxx")) do
    -- 获取源文件的文件名（去掉路径和扩展名）
    local targetname = path.basename(sourcefile)

    -- 为每个源文件创建一个可执行文件
    target(targetname)
        set_kind("binary") -- 可执行文件
        add_files(sourcefile, os.files("src/header/codec/*.cc"))
        -- 添加预编译头文
        add_cxflags("-Winvalid-pch")
        add_headerfiles("<algorithm>", "<atomic>", "<condition_variable>", "<cstdlib>", "<cstring>",
                        "<dirent.h>", "<filesystem>", "<fstream>", "<functional>", "<future>",
                        "<memory>", "<mutex>", "<random>", "<sstream>", "<stdexcept>", "<string>",
                        "<thread>", "<unistd.h>", "<unordered_map>", "<vector>")
        add_cxflags("-finput-charset=UTF-8", "-fexec-charset=UTF-8", "-Wno-nested-anon-types",
                        "-Wall", "-Wextra", "-Wno-gnu-anonymous-struct", "-Wpedantic",
                        "-Wno-unused-parameter", "-Wno-gnu-zero-variadic-macro-arguments",
                        "-Wno-sign-compare")
        -- 链接库
        add_links("pthread", "fmtlog-static", "fmt", "muduo_net", "muduo_base", "gtest", 
                  "protobufProtocol", "protobuf", "sqlite3", "jsoncpp","z")
end
